package com.graduation.fq.teacher.logic;

import com.graduation.fq.teacher.interfaces.EventListener;
import com.graduation.fq.teacher.interfaces.ResponseListener;
import com.graduation.fq.teacher.module.MessageEventArgs;
import com.graduation.fq.teacher.module.SimpleEventArgs;
import com.graduation.fq.teacher.process.MsgGetProcess;
import com.graduation.fq.teacher.utils.MsgIndex;

/**
 * @author jifang
 * @version 2016/5/22.
 */
public class MessageLogic extends BaseLogic {
    private static MessageLogic instance;

    public static MessageLogic getInstance() {
        if (instance == null) {
            instance = new MessageLogic();
        }
        return instance;
    }

    public void getMessageCount(String teacherId, final EventListener listener){
        final MsgGetProcess process = new MsgGetProcess(MsgIndex.NEW_COUNT, teacherId);
        process.runGet(new ResponseListener() {
            @Override
            public void onResponse(String requestId) {
                SimpleEventArgs<Integer> args = new SimpleEventArgs<>(process.getStatus(), process.getCount());
                fireEvent(args, listener);
            }
        });
    }

    /**
     * 获取留言
     *
     * @param teacherId
     * @param listener
     */
    public void getMessages(String teacherId, final EventListener listener) {
        final MsgGetProcess process = new MsgGetProcess(MsgIndex.RECV, teacherId);
        process.runGet(new ResponseListener() {
            @Override
            public void onResponse(String requestId) {
                MessageEventArgs args = new MessageEventArgs(process.getStatus());
                args.setMessageMap(process.getMessages());
                fireEvent(args, listener);
            }
        });
    }
}
